﻿@using hc.epm.DataModel.Basic;
@using System.Collections.Generic;
@using hc.Plat.Common.Extend
@using hc.epm.Common;
@model List<Base_Company>
@{
    ViewBag.Title = "单位管理";
}
<div class="contentData">
    <div class="form-select c">
        <form method="post">
            <div>
                <div><label>单位名称 : </label><input type="text" name="Name" value="@ViewBag.Name" autocomplete="off" id="Name"></div>
                <div>
                    <label>单位类型 : </label>
                    <div class="layui-input-inline" style="float:right;margin:0 49% 0 0">
                        @Html.DropDownList("Type", ViewBag.CompanyType as SelectList)
                    </div>
                </div>
            </div>
            <div class="form-sub">
                <button type="submit">查询</button>
            </div>
        </form>
    </div>
    <div>
        <table class="datalist" style="word-break:break-all;word-wrap:break-word">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>单位编码</th>
                    <th>单位名称</th>
                    <th>单位类型</th>
                    <th>单位层级</th>
                    <th>父级单位编码</th>
                    <th>父级单位名称</th>
                    <th>单位地址</th>
                    <th>单位电话</th>
                    <th>联系人</th>
                    <th>联系人电话</th>
                    <th width="110">操作</th>
                </tr>
            </thead>
            <tbody>
                @{
                    int index = (ViewBag.pageIndex - (ViewBag.pageIndex - 1)) * ((ViewBag.pageIndex - 1) * 10);
                }
                @if (Model != null && Model.Count() > 0)
            {
                foreach (var item in Model)
                {
                    index++;
                        <tr>
                            <td class="table-center">@index</td>
                            <td>@item.Code</td>
                            <td>@item.Name</td>
                            <td>@(item.Type.ToEnumReq<RoleType>().GetText())</td>
                            @if (item.Type == "Owner" && item.PId == 0)
                            {
                                <td>总公司</td>
                            }
                            else {
                                <td>分公司</td>
                            }
                            <td>@item.PreCode</td>
                            <td>@item.PreName</td>
                            <td>@item.AddressInfo</td>
                            <td>@item.Phone</td>
                            <td>@item.Phone</td>
                            <td>@item.Phone</td>
                            <td class="table-center">
                                <a href="javascript:;" class="detail" data-itemid="@item.Id" >查看</a>
                            </td>
                        </tr>
                    }
                }
                else
                {
                    <tr>
                        <td colspan="12" class="table-center">
                            暂无数据
                        </td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div id="page" style="text-align:right; margin-right:5px;">
        
    </div>
</div>
<script>
    //若无数据隐藏分页组件
    if ('@ViewBag.Total' == 0) {
        $("#page").hide();
    }
    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        //分页
        laypage.render({
            elem: 'page',
            count: '@ViewBag.Total',
            curr: '@ViewBag.pageIndex',
            layout: ['prev', 'page', 'next', 'skip', 'count'],
            jump: function (obj, first) {
                if (!first) {
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    var search = $("form").serialize();
                    window.location.href = "/Company/Index?pageIndex=" + curr + "&" + search;
                }
            }
        });
        //查看
        $("table").on('click', '.detail', function () {
            var id = $(this).data('itemid');
            location.href = '/Company/Detail?id=' + id;
        });
    })
</script>

